package com.xinqi.modules.sys.job;

import com.xinqi.common.base.utils.uuids.UUIDs;
import com.xinqi.modules.sys.complaint.service.ComplaintService;
import com.xinqi.modules.sys.stats.service.HomePageDayStService;
import com.xinqi.modules.sys.stats.service.SchoolTeachingDayStService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 数据统计定时刷新任务
 *
 * @author linkai
 * @date 2023/5/15
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class DataStatsJob {
    private final HomePageDayStService homePageDayStService;

    private final SchoolTeachingDayStService schoolTeachingDayStService;

    private final ComplaintService complaintService;

    /**
     * 更新首页统计数据任务
     */
    @XxlJob("DataStatsJob_updateHomePageData")
    public ReturnT<String> updateHomePageData() throws Exception {
        String uid = UUIDs.uuidStr();
        log.debug("job executor! {}, 更新首页统计数据任务-开始", uid);
        homePageDayStService.updateToday();
        log.debug("job executor! {}, 更新首页统计数据任务-结束", uid);
        return ReturnT.SUCCESS;
    }

    /**
     * 定时任务 -- 账号解封
     *
     * @throws Exception
     */
    @XxlJob("accountUnblocking")
    public ReturnT<String> accountUnblocking() throws Exception {
        String uid = UUIDs.uuidStr();
        log.debug("job executor! {}, 账号解封定时任务-开始", uid);
        complaintService.accountUnblocking();
        log.debug("job executor! {}, 账号解封定时任务-结束", uid);
        return ReturnT.SUCCESS;
    }

    /**
     * 更新学校教学数据-级联更新班级教学数据
     */
    @XxlJob("DataStatsJob_updateSchoolTeachingData")
    public ReturnT<String> updateSchoolTeachingData() throws Exception {
        String uid = UUIDs.uuidStr();
        log.debug("job executor! {}, 更新学校教学数据-开始", uid);
        schoolTeachingDayStService.updateToday();
        log.debug("job executor! {}, 更新学校教学数据-结束", uid);
        return ReturnT.SUCCESS;
    }
}
